//div视野拖拽
function moveDivs(containert_id,content){
	var _id = (new Date()).valueOf();
	 $("#"+containert_id).append('<div id="'+_id+'" class="drag_main_box"><span class="icon iconfont-sm drag_span">&#xe747;</span><div class="drag_box" contenteditable="true" style="-webkit-user-select:text" >'+content+'</div></div>');
	var _block = document.getElementById(_id);
	//初始化左偏移，初始化上偏移，元素上偏移，元素左偏移，元素宽度，元素长度
	var _init_left,_init_top,_div_top,_div_left,_box_width,_box_heiht;
	//设备长度和宽度
	var _win_height = $("#"+containert_id).height();
	var _win_width = $("#"+containert_id).width();


	_block.addEventListener('touchstart', function(e) {
		// 拿到元素初始化X、Y轴坐标
      _init_left =  parseInt(e.touches[0].clientX);
      _init_top =  parseInt(e.touches[0].clientY);
      // 基于body的上偏移、左偏移
	  _div_top = $("#"+_id).offset().top - $("#"+containert_id).scrollTop();
      _div_left = $("#"+_id).offset().left;
      console.log();
      // 元素宽度、长度
      _box_width = $("#"+_id).width();
      _box_heiht = $("#"+_id).height();
    },{ passive: false });



    _block.addEventListener('touchmove', function(e) {
    	//阻止元素发生默认的行为
    	e.preventDefault();
    	// 获取元素移动X、Y轴坐标
      var _left = parseInt(e.touches[0].clientX);
      var _top = parseInt(e.touches[0].clientY);

      // 元素需要移动，左偏移量= 元素初始左偏移+（偏移x-初始偏移x）,上偏移量= 元素初始上偏移+（偏移y-初始偏移y）,
      var _need_left = _div_left + (_left - _init_left);
      var _need_top =_div_top +  (_top - _init_top);
      
      //检测_block是否还存在可视区域
      var _max_left = _win_width - _box_width;
      //var _max_top = _win_height - _box_heiht;
      var _min_top = $("#header").height();
      var _max_top = $(window).height()-$("#nav").height() - _box_heiht;

      if(_need_left < 0) _need_left = 0;
      if(_need_left > _max_left) _need_left = _max_left;

      if(_need_top < _min_top) _need_top = _min_top;
      if(_need_top > _max_top) _need_top = _max_top;
  	  $('#'+_id).css({
  	  	'top':_need_top+'px',
  	  	'left':_need_left+'px',
  		'z-index':999,
  	  })
  	  console.log(_need_top,_need_left);
	  
    },{ passive: false });

    _block.addEventListener('touchend', function(e) {
      	console.log( " ====> ");
      	console.log($("#"+_id).offset().top - $("#"+containert_id).scrollTop(), $("#"+_id).offset().left);
    });
}

//保留多位小数
function fixedNum(_val,_num = 2){
	var val = (_val * 100) / 100;
	return val.toFixed(_num);
}
